<?php
require 'Admin/Controller/Controller.php ';
require 'Admin/Model/UserModel.php';
class UserController extends Controller{
	function __Construct(){
		parent::__Construct();
		$this->mod = 'users';
	}
	function userlist(){

		$model = new UserModel();
		$data = $model->getUserList();
		$this->assign('users',$data);
		$this->display(); 
		//return $data;

	}
	function userform(){
		$this->display();
	}
	function add(){
		$data = $_POST;
		$model = new UserModel();
		$result = $model->addUser($data);
		if($result){
			echo '添加成功 <a href="admin.php?c=user&m=userlist">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=userlist'");
		}
		else{
			echo "添加失败！<br/>";
  			echo "<a href='admin.php?c=user&m=form'>返回</a>";
		}
	}
	function useredit(){
		$id = $_GET['id'];
		$model = new UserModel();
		$result = $model->getUserByID($id);
		$this->assign('user',$result);
		$this->display(); 
	}

	function update(){
		$data = $_POST;
		$model = new UserModel();
		$result = $model->updateUser($data);
		if($result){
			echo '更新成功 <a href="admin.php?c=user&m=userlist">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=userlist'");
		}
		else{
			echo "更新失败！<br/>";
  			echo "<a href='admin.php?c=user&m=mod&id=".$data['id']."'>返回</a>";
		}
	}
	function userdel(){
		$id = $_GET['id'];
		$model = new UserModel();
		$result = $model->delUser($id);
		if($result){
			echo '删除成功 <a href="admin.php?c=user&m=userlist">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=userlist'");
		}
		else{
			echo "删除失败！<br/>";
  			echo "<a href='admin.php?c=user&m=userlist'>返回</a>";
		}
	}
	function search(){
		$one=$_POST;
		//var_dump($one);
		$model= new UserModel();
		$data= $model->Search($one['key']);
		if($data){
			$this->assign('users',$data);
			$this->display();
		}
		else{
			echo "没有数据！<br/>";
			echo "<a href='admin.php?c=user&m=userlist'>返回</a>";
		}
		
	}


}
?>